import urllib.request
import urllib.parse
import json

countent = input("请输入要翻译的内容:")

# 请求地址
url = "http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule&sessionFrom=http://youdao.com/"
# 请求参数
data = {}
data['type'] = 'AUTO'
data['i'] = 'hello word'
data['doctype'] = 'json'
data['xmlVersion'] = '1.6'
data['keyfrom'] = 'fanyi.web'
data['ue'] = 'UTF-8'
data['typoResult'] = 'true'
data = urllib.parse.urlencode(data).encode("utf-8")

response = urllib.request.urlopen(url, data)
html = response.read().decode("utf-8")

print(html)
target = json.loads(html)
print("翻译结果：%s" % (target['errorCode']))